<?php
/**
* 
*/
class Machine_order_refund_model extends CI_Model
{
	private $_table = 'machine_order_refund';
	

	public function insertBatch($macIds, $orderId, $status)
	{
		$data = array();
		$now = date('Y-m-d H:i:s');

		foreach ($macIds as $key=>$value) {
			$data[$key]['mac_id'] 	  = $value;
			$data[$key]['order_id']   = $orderId;
			$data[$key]['status'] 	  = $status;
			$data[$key]['flag'] 	  = 0;
            $data[$key]['mac_state']  = 0;
			$data[$key]['created_at'] = $now;
			$data[$key]['updated_at'] = '0000-00-00 00:00:00';
		}

		return $this->db->insert_batch($this->_table, $data);
	}

	/**
	 * 查找订单是否存在,存在表示以前退过  但是被打回来了
	 */
	public function findByOrderId($orderId)
	{
		$this->db->select('id');
		$this->db->from($this->_table);
		$this->db->where('order_id', $orderId);
		$this->db->limit(1);
		return $this->db->get();
	}

	/**
	 * 修改订单状态
	 */
	public function updateStatus($orderId, $status)
	{
		$this->db->where('order_id', $orderId);
		return $this->db->update($this->_table, array('status' => $status, 'flag' => 0, 'mac_state' => 0));
	}

}




